programming:c:format string flagsWhat links here?
%[parameter][flags][width][.precision][length]type

|^type ^Output ^Example || ||c |Character |a || ||d or i |Signed decimal integer |392 || ||e |Scientific notation (mantise/exponent) using e character |3.9265e2 || ||E |Scientific notation (mantise/exponent) using E character |3.9265E2 || ||f |Decimal floating point |392.65 || ||g |Use shorter %e or %f |392.65 || ||G |Use shorter %E or %f |392.65 || ||o |Signed octal |610 || ||s |String of characters |sample || ||u |Unsigned decimal integer |7235 || ||x |Unsigned hexadecimal integer |7fa || ||X |Unsigned hexadecimal integer (capital letters) |7FA || ||p |Address pointed by the argument |B800:0000 || ||n |Nothing printed. The argument must be a pointer to integer where the number of characters written so far will be stored.| ||

flagsmeaning
- Left align within the given width. (right align is the default).
+ Forces to preceed the result with a sign (+ or -) if signed type. (by default only - (minus) is printed).
blank If the argument is a positive signed value, a blank is inserted before the number.
# Used with o, x or X type the value is preceeded with 0, 0x or 0X respectively if non-zero.
Used with e, E or f forces the output value to contain a decimal point even if only zeros follow.
Used with g or G the result is the same as e or E but trailing zeros are not removed.


width meaning
number Minimum number of characters to be printed. If the value to be printed is shorter than this number the result is padded with blanks. The value is never truncated even if the result is larger.
0numberSame as above but filled with 0s instead of blanks.
* The width is not specified in the format string, it is specified by an integer value preceding the argument thas has to be formatted.




.precisionmeaning
.number for d, i, o, u, x, X types: precision specifies the minimum number of decimal digits to be printed. If the value to be printed is shorter than this number the result is padded with blanks. The value is never truncated even if the result is larger.(if nothing specified default is 1).
for e, E, f types: number of digits to be printed after the decimal point. (if nothing specified default is 6).
for g, G types : maximum number of significant numbers to be printed.
for s type: maximum number of characters to be printed. (default is to print until first null character is encountered).
for c type : (no effect).




length meaning (affects on how arguments are interpreted by the function)
hhFor integer types, causes printf to expect an int sized integer argument which was promoted from a char.
h For integer types, causes printf to expect a int sized integer argument which was promoted from a short
l For integer types, causes printf to expect a long sized integer argument.
llFor integer types, causes printf to expect a long long sized integer argument.
L For floating point types, causes printf to expect a long double argument.
zFor integer types, causes printf to expect a size_t sized integer argument.
jFor integer types, causes printf to expect a intmax_t sized integer argument.
tFor integer types, causes printf to expect a ptrdiff_t sized integer argument.
programming:c:format string flags
filename:programming:c:format string flags
filename:programming%3Ac%3Aformat%20string%20flags
last edit:January 23 2011 15:34:18 (4851 days ago)
ct = 1714947766.000000 = May 05 2024 18:22:46
ft = 1295814858.000000 = January 23 2011 15:34:18
dt = 419132908.000000